package com.rongshu.view.login.presenter;

import android.content.Context;

import com.rongshu.api.FileUploadService;
import com.rongshu.api.RetorfitService;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.login.contract.QuestionFeedbackView;
import com.rongshu.view.login.entity.QuestionFeedback;
import com.rongshu.view.login.entity.ReportClass;
import com.rongshu.view.userInfo.entity.UpLoadImage;

import java.util.Map;

import okhttp3.RequestBody;
import retrofit2.http.PartMap;
import rx.Subscriber;
import rx.functions.Action0;

public class QuestionFeedbackPrensenter extends BasePresenter<QuestionFeedbackView> {

    public QuestionFeedbackPrensenter(Context context) {
        super(context);
    }

    /**
     * 1反馈2举报用户/3举报文章/4举报贴子
     *
     * @param user_id
     * @param type
     * @param user_id_to
     * @param reporttype
     * @param sign
     * @param reportClass
     */
    public void postReportUser(int user_id, int type, int user_id_to,
                               int reporttype, String sign, ReportClass reportClass) {
        RetorfitService.postReportUser(user_id, type, user_id_to, reporttype, sign, reportClass)
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {

                    }
                })
                .subscribe(new Subscriber<QuestionFeedback>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(QuestionFeedback questionFeedback) {
                        if(getView()!=null){
                            getView().onQuestionFeedback(questionFeedback);
                        }
                    }
                });

    }

    /**
     * 图片上传
     */
    public void postUploadMoreFile(@PartMap Map<String, RequestBody> files) {
        FileUploadService.uploadMoreFile(files)
                .subscribe(new Subscriber<UpLoadImage>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(UpLoadImage upLoadImage) {
                        if (getView() != null) {
                            getView().uploadImageResult(upLoadImage);
                        }
                    }
                });
    }

}
